package com.chuyangc.qdms.controller;

import com.chuyangc.qdms.entity.Transport;
import com.chuyangc.qdms.service.TransportService;
import com.chuyangc.qdms.vo.TransVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 欧楚杨
 * @since 2022-05-31
 */
@RestController
@RequestMapping("/chuyangc/transport")
@Api(tags = "物流相关的请求")
public class TransportController {
    @Autowired
    TransportService transportService;

    @GetMapping("/pagesendlist/{pageNum}")
    @ApiOperation("获取物流状态为发货中的列表每页显示十条记录")
    public PageInfo<Transport> pageListTransportsend(@PathVariable String pageNum){
        int pageSize = 10;
        PageHelper.startPage(Integer.parseInt(pageNum),pageSize);
        List<Transport> transporttypesend = transportService.getTransporttypesend();
        PageInfo<Transport> transportPageInfo = new PageInfo<>(transporttypesend);
        return transportPageInfo;
    }

    @GetMapping("/pagetranslist/{pageNum}")
    @ApiOperation("获取物流状态为送货中的列表每页显示十条记录")
    public PageInfo<Transport> pageListTransporttrans(@PathVariable String pageNum){
        int pageSize = 10;
        PageHelper.startPage(Integer.parseInt(pageNum),pageSize);
        List<Transport> transporttypetrans = transportService.getTransporttypetrans();
        PageInfo<Transport> transportPageInfo = new PageInfo<>(transporttypetrans);
        return transportPageInfo;
    }

    @GetMapping("/pagerecielist/{pageNum}")
    @ApiOperation("获取物流状态为已签收的列表每页显示十条记录")
    public PageInfo<Transport> pageListTransportrecie(@PathVariable String pageNum){
        int pageSize = 10;
        PageHelper.startPage(Integer.parseInt(pageNum),pageSize);
        List<Transport> transporttyperecie = transportService.getTransporttyperecie();
        PageInfo<Transport> transportPageInfo = new PageInfo<>(transporttyperecie);
        return transportPageInfo;
    }

    @PostMapping("/add")
    @ApiOperation("插入物流记录")
    public boolean addTrans(@RequestBody Transport transport){
        return transportService.save(transport);
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation("删除物流记录")
    public boolean delTrans(@PathVariable Integer id){
        return transportService.removeById(id);
    }

    @GetMapping("/transchart")
    @ApiOperation("不同物流状态下的记录数统计")
    public TransVO getCount(){
        return transportService.getCount();
    }

    @GetMapping("/total")
    @ApiOperation("获取所有物流记录的数量")
    public Integer getTotal(){
        return transportService.count();
    }

    @GetMapping("/list")
    @ApiOperation("获取所有物流记录")
    public List<Transport> getTranslist(){
        return transportService.list();
    }
}
